﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DynamicToSql
{
    public sealed class Property
    {
        private Property()
        { 
        
        }

        internal Property(string name)
        {
            this.Name = name;
            this.SqlFunction = null;
        }

        public Property Function(string sqlFunction)
        {
            this.SqlFunction = sqlFunction;
            return this;
        }

        public static Expression operator ==(Property property, object value)
        {
            var expression = new Expression(property, ComparisonOperator.Equal);
            expression.Values.Add(value);
            return expression;
        }

        public static Expression operator !=(Property property, object value)
        {
            var expression = new Expression(property, ComparisonOperator.NotEqual);
            expression.Values.Add(value);
            return expression;
        }

        public static Expression operator >(Property property, object value)
        {
            var expression = new Expression(property, ComparisonOperator.GreaterThan);
            expression.Values.Add(value);
            return expression;
        }

        public static Expression operator >=(Property property, object value)
        {
            var expression = new Expression(property, ComparisonOperator.GreaterThanOrEqual);
            expression.Values.Add(value);
            return expression;
        }

        public static Expression operator <(Property property, object value)
        {
            var expression = new Expression(property, ComparisonOperator.LessThan);
            expression.Values.Add(value);
            return expression;
        }

        public static Expression operator <=(Property property, object value)
        {
            var expression = new Expression(property, ComparisonOperator.LessThanOrEqual);
            expression.Values.Add(value);
            return expression;
        }

        public Expression Like(string value)
        {
            var expression = new Expression(this, ComparisonOperator.Like);
            expression.Values.Add(value);
            return expression;
        }

        public Expression In(params object[] values)
        {
            var expression = new Expression(this, ComparisonOperator.In);
            foreach (var value in values)
                expression.Values.Add(value);
            return expression;
        }

        public Expression In(IEnumerable<object> values)
        {
            return this.In(values.ToArray());
        }

        public Expression Between(object min, object max)
        {
            var expression = new Expression(this, ComparisonOperator.Between);
            expression.Values.Add(min);
            expression.Values.Add(max);
            return expression;
        }

        public override bool Equals(object obj)
        {
            return base.Equals(obj);
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        internal string Name { get; set; }

        internal string SqlFunction { get; set; }

    }
}
